TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file LegendTitle.php

Documentation is available at LegendTitle.php

  1. <?php
  2.  
  3. /**
  4.  * LegendTitle class
  5.  *
  6.  * Description: Legend title characteristics
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage legend
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16.  class LegendTitle extends TextShape {
  17.  
  18.     private $textAlign;
  19.     private $tmpFrameWidth;
  20.     private $tmpXPosTitle;
  21.     private $tmpMargin;
  22.     private $FontH;
  23.  
  24.     // Interceptors
  25.     function __get( $property ) {
  26.       $method ="get{$property}";
  27.       if ( method_exists( $this, $method ) ) {
  28.         return $this->$method();
  29.       }
  30.     }
  31.  
  32.     function __set ( $property,$value ) {
  33.       $method ="set{$property}";
  34.       if ( method_exists( $this, $method ) ) {
  35.         return $this->$method($value);
  36.       }
  37.     }
  38.  
  39.     /**
  40.     * The class constructor.
  41.     */
  42.     public function LegendTitle($c) {
  43.             $this->textAlign = Array(StringAlignment::$CENTER);
  44.  
  45.             parent::TextShape($c);
  46.  
  47.             $tmpColor = new Color(0,0,0);
  48.             $font = $this->getFont();
  49.             $font->setColor($tmpColor);
  50.             $font->setBold(true);
  51.             $font->getBrush()->setDefaultColor($tmpColor);
  52.             $this->getPen()->setVisible(false);
  53.     }
  54.  
  55.     // Determines if text is displayed at left, center or right side of chart legend title.
  56.     // Description("Horizontal alignment of displayed text.")
  57.  
  58.     public function getTextAlign()  {
  59.         return $this->textAlign;
  60.     }
  61.  
  62.     public function setTextAlign($value) {
  63.         if ($this->textAlign!=$value) {
  64.             $this->textAlign=$value;
  65.             $this->invalidate();
  66.         }
  67.     }
  68.  
  69.     public function calcHeight() {
  70.         $this->getChart()->getGraphics3D()->getFont()->assign($this->getFont());
  71.         $this->setHeight(MathUtils::round($this->getChart()->getGraphics3D()->textHeight("W") * sizeof($this->lines)));
  72.  
  73.         if(!$this->getTransparent()) {
  74.             $this->setHeight($this->getHeight()+2);
  75.             if ($this->getPen()->getVisible())
  76.                 $this->setHeight($this->getHeight()+(2 * $this->getPen()->getWidth()));
  77.             }
  78.     }
  79.  
  80.     public function drawLineTitle($AIndex) {
  81.         $tmparray = $this->lines;
  82.         $St=$tmparray[$AIndex];
  83.         $APos=$this->getShapeBounds()->getTop();
  84.         $APos+=($AIndex+1 * $this->FontH) + $this->tmpFrameWidth;
  85.  
  86.         if (in_array(StringAlignment::$FAR,$this->textAlign)) {
  87.             $this->tmpXPosTitle = $this->getShapeBounds()->getRight() - MathUtils::round($this->getChart()->getGraphics3D()->textWidth($St)) - ($this->tmpMargin / 2);
  88.         }
  89.         else
  90.         if (in_array(StringAlignment::$CENTER,$this->textAlign)) {
  91.             $this->tmpXPosTitle = MathUtils::round(($this->getShapeBounds()->getLeft()+$this->getShapeBounds()->getRight()) / 2) - MathUtils::round($this->getChart()->getGraphics3D()->textWidth($St) / 2);
  92.         }
  93.  
  94.         $this->getChart()->getGraphics3D()->textOut($this->tmpXPosTitle,$APos,0, $St, $this->textAlign);
  95.     }
  96.  
  97.     public function drawText() {
  98.         if($this->getPen()->getVisible())
  99.             $this->tmpFrameWidth=$this->getPen()->getWidth();
  100.         else
  101.             $this->tmpFrameWidth = 1;
  102.  
  103.         $this->tmpMargin = MathUtils::round($this->getChart()->getGraphics3D()->textWidth("W"));
  104.         $this->FontH = MathUtils::round($this->getChart()->getGraphics3D()->textHeight("W"));
  105.  
  106.         if (in_array(StringAlignment::$NEAR,$this->textAlign)) {
  107.             $this->tmpXPosTitle=$this->getShapeBounds()->getLeft() + ($this->tmpMargin/2);
  108.         }
  109.  
  110.         if ($this->getTextFormat() == TextFormatted::$NORMAL) {
  111.             for($t=0; $t < sizeof($this->lines); ++$t) {
  112.                 $this->drawLineTitle($t);
  113.             }
  114.         } else {
  115.             $this->getChart()->getGraphics3D()->setTextAlign($this->textAlign);
  116.             $this->getChart()->getGraphics3D()->textOut($this->tmpXPosTitle,$this->tmpFrameWidth+$this->getShapeBounds()->getTop(),0,$this->getText());
  117.         }
  118.     }
  119.  
  120.     public function internalDraw($g, $Rect) {
  121.         $this->calcShapeBounds($Rect);
  122.         $this->drawRectRotated($g, $this->getShapeBounds(), 0, 0);
  123.         $this->drawText();
  124.     }
  125.  
  126.     public function getTotalWidth() {
  127.         $this->getChart()->getGraphics3D()->getFont()->assign($this->getFont());
  128.         $result = 0;
  129.         $tmpArray=$this->lines;
  130.         for($t=0; $t < sizeof($tmpArray); ++$t) {
  131.             $result=max($result,MathUtils::round($this->getChart()->getGraphics3D()->textWidth($tmpArray[$t])));
  132.         }
  133.         $result=$result+MathUtils::round($this->getChart()->getGraphics3D()->textWidth("W"));
  134.  
  135.         if(!$this->getTransparent()) {
  136.             if($this->getPen()->getVisible())
  137.                 $result += $this->getPen()->getWidth() * 2;
  138.             if($this->getShadow()->getVisible())
  139.                 $result += $this->getShadow()->getWidth();
  140.         }
  141.  
  142.         return $result;
  143.     }
  144.  
  145.     private function calcShapeBounds($R) {
  146.         $this->setShapeBounds(Rectangle::fromLTRB($R->getLeft()+2, $R->getTop() +2, $R->getRight()-2,$R->getTop()+4+ $this->getHeight()));
  147.         if(!$this->getTransparent() && $this->getShadow()->getVisible()) {
  148.             if($this->getShadow()->getWidth() > 0) {
  149.                 $this->setRight($this->getRight()-$this->getShadow()->getWidth());
  150.             } else {
  151.                 $this->shapeBounds->x-=$this->getShadow()->getWidth();
  152.             }
  153.  
  154.             if($this->getShadow()->getHeight() < 0) {
  155.                 $this->shapeBounds->y-=$this->getShadow()->getHeight();
  156.             }
  157.         }
  158.     }
  159. }
  160.  
  161. ?>

Documentation generated on Wed, 16 Jun 2010 12:06:49 +0200 by phpDocumentor 1.4.1